from django.db import models


# Create your models here.

class User(models.Model):
    '''
    User模型类，数据模型应该继承于models.Model或其子类
    '''
    # id = models.IntegerField(primary_key=True)  # 主键
    # id = models.AutoField(primary_key=True) # 自增长主键
    id = models.AutoField(primary_key=True)  # 自增长主键
    # id = models.BigAutoField(primary_key=True)  # student_id为主键

    username = models.CharField(max_length=30)  # 用户名，字符串类型
    email = models.CharField(max_length=30)  # 邮箱，字符串类型

    def __unicode__(self):
        return self.User


class Article(models.Model):
    '''
    Article模型类，数据模型应该继承于models.Model或其子类
    '''
    # id = models.IntegerField(primary_key=True)  # 主键
    id = models.AutoField(primary_key=True)  # 自增长主键-隐藏由系统完成填充
    title = models.CharField(max_length=120, verbose_name='标题')  # 标题，字符串类型
    content = models.TextField(verbose_name='内容')  # 内容，文本类型
    publish_date = models.DateTimeField(verbose_name='发布时间')  # 出版时间，日期时间类型
    user = models.ForeignKey(User, on_delete=models.CASCADE,verbose_name='作者')  # 设置外键

    def __unicode__(self):  # 这个似乎不用    https://blog.csdn.net/kong2030/article/details/82319936
        return self.Artice
